package reflecct;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @classname:ConstrucorDemo
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/23 22:54
 * @version: 0.1
 * @since:1.8
 */
public class ConstrucorDemo {
    public static void main(String[] args) {
        Integer id  = 1001;
        String name = "jim";
        String pass = "1234";
        String phone = "199201224445";

        Map<String,Object> map  = new LinkedHashMap<>(16);
        map.put("id",id);
        map.put("name",name);
        map.put("pass",pass);
        map.put("phone",phone);


        try {
            Class<?> aClass = Class.forName("reflecct.User");
            Constructor<?> constructor = aClass.getDeclaredConstructor(Integer.class, String.class, String.class, String.class);
            User user  = (User) constructor.newInstance(map.values().toArray(new Object[0]));
            System.out.println(user);

        } catch (ClassNotFoundException|NoSuchMethodException|IllegalAccessException|InstantiationException|InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
